var pname = $("#pname");
$(function(){
	setAutoComplete("#pcode");
});
      
function setAutoComplete(objId) {
    var obj = $(objId);
	obj.autocomplete({
		minLength : 3,
		source : function(request, response) {
			var term = request.term;
			$.getJSON(
					"../product/product!searchall", 
					{"term" : term}, 
					function(data) {
						response(data);
					}							
			);
		},
		focus : function(event, ui) {
			obj.val(ui.item.code);
			return false;
		},
		select : function(event, ui) {
			obj.val(ui.item.code);		
			pname.val(ui.item.name);
			return false;
		}

	}).data("autocomplete")._renderItem = function(ul, item) {
		return $("<li></li>").data("item.autocomplete", item).append(
				"<a>" + item.code + "|" + item.name + "</a>").appendTo(ul);
	};
}
var par = window.dialogArguments; 
function addRow(){
	
    var sumt  = $("#psubmit").val();
    var rmk      = $("#premark").text();
    var valid = sumt && rmk;
    
    if(!valid){
    	alert("缴库数和备注必须同时填写!");
    	return;
    }  
	
	par.addDataLine(
			$("#pcode").val(), 
			$("#pname").val(),
			$("#plocal").val(),
			$("#psubmit").val(), 
			$("#premark").text());
}